//app.js
var util = require('/utils/util.js')
App({
 getUserInfo:function(){
    var that = this
      //调用登录接口
      wx.login({
        success: function (LoginRes) {
          //获取openID
          var loginUrl = "https://api.weixin.qq.com/sns/jscode2session?";
          var dataInfo = {
            appid: "wx1ce78c19b2165e17",
            secret: "627298f05ed62045de8dcd9eeb902ee8",
            js_code: LoginRes.code,
            grant_type: "authorization_code",
          }
          util.HttpGet(loginUrl, dataInfo, function (response) {
            try {
                wx.setStorageSync('openid', response.openid);
            } catch (e) {
            }
          });
          //获取基础信息
          // wx.getUserInfo({
          //   success: function (res) {
          //     // console.log(res);
          //     // console.log(wx.getStorageSync("openid"));
          //     that.globalData.userInfo = res.userInfo
          //   }
          // })
        }
      })

  },
  onLaunch: function () {
   // this.getUserInfo();
   wx.cloud.init({
     env:'xgp-zlgga'
   });
   this.getopenid();
  },
    getopenid() {
        wx.cloud.callFunction(
            {
                name: "getopenid",
                success(res) {
                    console.log("openid获取成功",res.result.openid);
                    try {
                        wx.setStorageSync('openid', res.result.openid);
                        wx.setStorageSync('Bill', "");
                    } catch (e) {
                    }
                },
                fail(err) {
                    console.log("openid获取失败",err)
                }
            },
        )
    },
  //
  // globalData:{
  //   userInfo:null
  // }
})
